package com.zzx.business.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzx.business.domain.BusinessFreightOrder;
import com.zzx.business.vo.BusinessFreightOrderVo;
import com.zzx.business.vo.BusinessProductVo;
import com.zzx.business.vo.BusinessSiteVo;
import com.zzx.common.core.domain.entity.SysDept;
import com.zzx.common.core.domain.entity.SysUser;
import com.zzx.common.exception.base.BaseException;
import com.zzx.common.utils.DateUtils;
import com.zzx.common.utils.uuid.IdUtils;
import com.zzx.system.mapper.SysDeptMapper;
import com.zzx.system.service.ISysDeptService;
import com.zzx.system.service.ISysUserService;
import org.apache.commons.math3.stat.descriptive.summary.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ProductService {

    @Autowired
    private IBusinessFreightOrderService businessFreightOrderService;


    public boolean save(BusinessFreightOrderVo entity) {
        String s = IdUtils.fastUUID();
        entity.setCheckNo(s);
        entity.setStatus("1");
        BigDecimal limitWeight = entity.getLimitWeight();
        BigDecimal weightSum = entity.getWeightSum();
        BigDecimal weightTruck = entity.getWeightTruck();
        BigDecimal subtract = new BigDecimal(0);
        if(weightSum != null && weightTruck != null){
            subtract = weightSum.subtract(weightTruck).setScale(2);
            entity.setWeightNet(subtract);
        }
        if (limitWeight != null){
            if (limitWeight.compareTo(subtract) < 0) {
                entity.setIsOverWeight("Y");
            } else {
                entity.setIsOverWeight("N");
            }
        } else {
            entity.setIsOverWeight("N");
        }

        entity.setStartTime(DateUtils.getNowDate());
        businessFreightOrderService.save(entity);
        return true;
    }

    public boolean isPass(BusinessFreightOrderVo entity) {
        entity.setStatus("2");
        entity.setEndTime(DateUtils.getNowDate());
        businessFreightOrderService.updateById(entity);
        return true;
    }


}
